package cn.controller;

import cn.entity.Qualification;
import cn.entity.QualificationCondition;
import cn.entity.Result;
import cn.service.QulificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@RestController
@RequestMapping("/qualification")
public class QualificationController {

    @Autowired
    QulificationService qulificationService;

    @RequestMapping("index")
    public ModelAndView qualification(){
        return new ModelAndView("/qualification/index");
    }
    @RequestMapping("select/{pageNum}/{pageSize}")
    public Result select(@PathVariable("pageNum")int pageNum,@PathVariable("pageSize")int pageSize,@RequestBody QualificationCondition quaCondition){
        return new Result(true,"成功",qulificationService.selectPage(pageNum,pageSize,quaCondition));
    }

    @RequestMapping("/toUpdate")
    public ModelAndView toUpdate(){
        return new ModelAndView("qualification/update");
    }

    @RequestMapping("/selectOne/{id}")
    public Result selectOne(@PathVariable("id") Long id){
        return new Result(true,"成功",qulificationService.selectUpdate(id));
    }

    @RequestMapping("/check")
    public Result check(@RequestBody Qualification qua){
        qua.setAddress(null);
        qua.setUpdateDate(new Date());
        return new Result(true,"成功",qulificationService.updateByPrimaryKeySelective(qua));
    }
}
